package zhongbo.java.air.flightpath.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import zhongbo.java.air.flightpath.listener.RedisSubscribeIngestFlightPathChanelListener;
import zhongbo.java.air.flightpath.listener.RedisSubscribeLogChanelListener;

/**
 * 说明：
 * 配置redis Sub订阅监听者listener
 *
 * @author 钟波dellNotebook
 * @since 2025年04月01日 星期二 21:50:50
 */
@Configuration
@Slf4j
public class RedisListenerConfig {

    /**
     * 日志频道
     */
    public static String LOG_CHANEL = "log_chanel";

    /**
     * 数据引接清洗后的航迹数据频道
     */
    public static String INGEST_NAME_OF_CHANEL = "ingest_flight_path_chanel_zhongbo";

    /**
     * 最新实时航迹点位信息
     */
    public static String LIVE_NAME_OF_CHANEL = "live_flight_path_zhongbo";

    /**
     * 配置redis listenerContainer 监听容器, 添加 logChanelListener 监听器到容器里, 同时指定 chanel 名称为 log_chanel
     *
     * @param listenerContainer 注入 listenerContainer
     *                          (在common模块里,我已配置了这个bean,这里直接使用即可)
     * @param logChanelListener redis日志频道监听器
     *                          (自建RedisLogSubscribeListener类,继承了MessageListener接口)
     */
    @Autowired
    public void configListener(RedisMessageListenerContainer listenerContainer
            , RedisSubscribeLogChanelListener logChanelListener
            , RedisSubscribeIngestFlightPathChanelListener flightPathChanelListener
    ) {
        log.info("配置redis监听器");
        // 配置 redisLogSubscribeListener 监听频道 log_chanel 接收消息
        Topic logTopic = new PatternTopic(LOG_CHANEL);
        Topic pathTopic = new PatternTopic(INGEST_NAME_OF_CHANEL);
        listenerContainer.addMessageListener(logChanelListener, logTopic);
        listenerContainer.addMessageListener(flightPathChanelListener, pathTopic);
    }

}
